package com.bingqing.controller;

import cn.hutool.core.date.DateUtil;
import com.bingqing.common.AutoLog;
import com.bingqing.common.Result;
import com.bingqing.dao.HotelDao;
import com.bingqing.dao.NoticeDao;
import com.bingqing.entity.Hotel;
import com.bingqing.entity.Notice;
import com.bingqing.entity.Params;
import com.bingqing.entity.Reserve;
import com.bingqing.service.NoticeService;
import com.bingqing.service.ReserveService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: TypeController
 * Package: com.bingqing.controller
 * Description:
 *
 * @Author liuyujie
 * @Create 2024-03-10 9:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    NoticeService noticeService;

    @Resource
    NoticeDao noticeDao;

    //分页查询
    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Notice> info = noticeService.findBySearch(params);
        return Result.success(info);
    }
    //查询所有
    @GetMapping()
    public Result findTop3() {
        List<Notice> info = noticeDao.findTop3();
        return Result.success(info);
    }


    //新增
    @PostMapping("/add")
    @AutoLog("新增公告")
    public Result add(@RequestBody Notice notice) {
        notice.setCreateTime(DateUtil.now());
        notice.setUpdateTime(DateUtil.now());
        noticeService.add(notice);
        return Result.success();
    }

    //编辑
    @PostMapping("/edit")
    @AutoLog("编辑公告")
    public Result edit(@RequestBody Notice notice) {
        notice.setUpdateTime(DateUtil.now());
        noticeService.update(notice);
        return Result.success();
    }
    //删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        noticeService.deleteById(id);
        return Result.success();
    }

}
